/* ** por compatibilidad se omiten tildes **
================================================================================
 TRABAJO PRACTICO 3 - System Programming - ORGANIZACION DE COMPUTADOR II - FCEN
================================================================================
  definicion de la tabla de descriptores globales
*/
#include "defines.h"
#include "gdt.h"
#include "tss.h"

gdt_entry gdt[GDT_COUNT] = {
	/* Descriptor nulo*/
	/* Offset = 0x00 */
	[GDT_IDX_NULL_DESC] = (gdt_entry) {
		(unsigned short)	0x0000,			/* limit[0:15]  */
		(unsigned short)	0x0000,			/* base[0:15]   */
		(unsigned char)		0x00,			/* base[23:16]  */
		(unsigned char)		0x00,			/* type         */
		(unsigned char)		0x00,			/* s            */
		(unsigned char)		0x00,			/* dpl          */
		(unsigned char)		0x00,			/* p            */
		(unsigned char)		0x00,			/* limit[16:19] */
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x00,			/* db           */
		(unsigned char)		0x00,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */
},	
{
		/*primer registro* nivel 0 codigo*/
		(unsigned short)	0xffff,			/* limit[0:15]  */
		(unsigned short)	0x0000,			/* base[0:15]   */
		(unsigned char)		0x00,			/* base[23:16]  */
		(unsigned char)		0xA,			/* type         */
		(unsigned char)		0x1,			/* s            */
		(unsigned char)		0x0,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x7,			/* limit[16:19] */
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x1,			/* db           */
		(unsigned char)		0x1,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */
},
{
		/*segundo registro* nivel 0 datos*/
		(unsigned short)	0xffff,			/* limit[0:15]  */
		(unsigned short)	0x0000,			/* base[0:15]   */
		(unsigned char)		0x00,			/* base[23:16]  */
		(unsigned char)		0x2,			/* type         */
		(unsigned char)		0x1,			/* s            */
		(unsigned char)		0x0,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x7,			/* limit[16:19] */
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x1,			/* db           */
		(unsigned char)		0x1,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */
},
{
		/*tercero registro* nivel 2 codigo*/
		(unsigned short)	0xffff,			/* limit[0:15]  */
		(unsigned short)	0x0000,			/* base[0:15]   */
		(unsigned char)		0x00,			/* base[23:16]  */
		(unsigned char)		0xA,			/* type         */
		(unsigned char)		0x1,			/* s            */
		(unsigned char)		0x2,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x7,			/* limit[16:19] */
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x1,			/* db           */
		(unsigned char)		0x1,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */
},
{
		/*cuarto registro* nivel 2 datos*/
		(unsigned short)	0xffff,			/* limit[0:15]  */
		(unsigned short)	0x0000,			/* base[0:15]   */
		(unsigned char)		0x00,			/* base[23:16]  */
		(unsigned char)		0x2,			/* type         */
		(unsigned char)		0x1,			/* s            */
		(unsigned char)		0x2,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x7,			/* limit[16:19] */
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x1,			/* db           */
		(unsigned char)		0x1,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */
},
{
		/*quinto registro* nivel 3 codigo*/
		(unsigned short)	0xffff,			/* limit[0:15]  */
		(unsigned short)	0x0000,			/* base[0:15]   */
		(unsigned char)		0x00,			/* base[23:16]  */
		(unsigned char)		0xA,			/* type         */
		(unsigned char)		0x1,			/* s            */
		(unsigned char)		0x3,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x7,			/* limit[16:19] */
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x1,			/* db           */
		(unsigned char)		0x1,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */
},
{
		/*sexto registro* nivel 3 datos*/
		(unsigned short)	0xffff,			/* limit[0:15]  */
		(unsigned short)	0x0000,			/* base[0:15]   */
		(unsigned char)		0x00,			/* base[23:16]  */
		(unsigned char)		0x2,			/* type         */
		(unsigned char)		0x1,			/* s            */
		(unsigned char)		0x3,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x7,			/* limit[16:19] */
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x1,			/* db           */
		(unsigned char)		0x1,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */

},
{
		/*segmento de pantalla* nivel 0 datos*/
		(unsigned short)	0xfA0,			/* limit[0:15]  */
		(unsigned short)	0x8000,			/* base[0:15]   */
		(unsigned char)		0x0B,			/* base[23:16]  */
		(unsigned char)		0x2,			/* type         */
		(unsigned char)		0x1,			/* s            */
		(unsigned char)		0x0,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x0,			/* limit[16:19] */
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x1,			/* db           */
		(unsigned char)		0x0,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */
},
{
		/* TSS Tarea Inicial */
		(unsigned short)	0x0000,			/* limit[0:15]  */
		(unsigned short)	0x0000,			/* base[0:15]   */
		(unsigned char)		0x00,			/* base[23:16]  */
		(unsigned char)		0x09,			/* type         */
		(unsigned char)		0x00,			/* s            */
		(unsigned char)		0x00,			/* dpl          */
		(unsigned char)		0x01,			/* p            */
		(unsigned char)		0x00,			/* limit[16:19] */
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x00,			/* db           */
		(unsigned char)		0x00,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */
},	
{
		/*TSS Tarea Idle*/
		(unsigned short)	0x00,			/* limit[0:15]  */				// se inicializa en tss.c
		(unsigned short)	0x00,			/* base[0:15]   */				// se inicializa en tss.c
		(unsigned char)		0x00,			/* base[23:16]  */				// se inicializa en tss.c
		(unsigned char)		0x09,			/* type         */
		(unsigned char)		0x0,			/* s            */
		(unsigned char)		0x0,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x0,			/* limit[16:19] */				// estamos seguros que 16 bits nos alcanzan para cubrir sizeof(tss)
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x0,			/* db           */
		(unsigned char)		0x0,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */				// se inicializa en tss.c
},
{
		/*TSS Tarea 1*/
		(unsigned short)	0x00,			/* limit[0:15]  */				// se inicializa en tss.c
		(unsigned short)	0x00,			/* base[0:15]   */				// se inicializa en tss.c
		(unsigned char)		0x00,			/* base[23:16]  */				// se inicializa en tss.c
		(unsigned char)		0x09,			/* type         */
		(unsigned char)		0x0,			/* s            */
		(unsigned char)		0x3,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x0,			/* limit[16:19] */				// estamos seguros que 16 bits nos alcanzan para cubrir sizeof(tss)
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x0,			/* db           */
		(unsigned char)		0x0,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */				// se inicializa en tss.c
},
{
		/*TSS Tarea 2*/
		(unsigned short)	0x00,			/* limit[0:15]  */				// se inicializa en tss.c
		(unsigned short)	0x00,			/* base[0:15]   */				// se inicializa en tss.c
		(unsigned char)		0x00,			/* base[23:16]  */				// se inicializa en tss.c
		(unsigned char)		0x09,			/* type         */
		(unsigned char)		0x0,			/* s            */
		(unsigned char)		0x3,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x0,			/* limit[16:19] */				// estamos seguros que 16 bits nos alcanzan para cubrir sizeof(tss)
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x0,			/* db           */
		(unsigned char)		0x0,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */				// se inicializa en tss.c
},
{
		/*TSS Tarea 3*/
		(unsigned short)	0x00,			/* limit[0:15]  */				// se inicializa en tss.c
		(unsigned short)	0x00,			/* base[0:15]   */				// se inicializa en tss.c
		(unsigned char)		0x00,			/* base[23:16]  */				// se inicializa en tss.c
		(unsigned char)		0x09,			/* type         */
		(unsigned char)		0x0,			/* s            */
		(unsigned char)		0x3,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x0,			/* limit[16:19] */				// estamos seguros que 16 bits nos alcanzan para cubrir sizeof(tss)
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x0,			/* db           */
		(unsigned char)		0x0,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */				// se inicializa en tss.c
},
{
		/*TSS Tarea 4*/
		(unsigned short)	0x00,			/* limit[0:15]  */				// se inicializa en tss.c
		(unsigned short)	0x00,			/* base[0:15]   */				// se inicializa en tss.c
		(unsigned char)		0x00,			/* base[23:16]  */				// se inicializa en tss.c
		(unsigned char)		0x09,			/* type         */
		(unsigned char)		0x0,			/* s            */
		(unsigned char)		0x3,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x0,			/* limit[16:19] */				// estamos seguros que 16 bits nos alcanzan para cubrir sizeof(tss)
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x0,			/* db           */
		(unsigned char)		0x0,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */				// se inicializa en tss.c
},
{
		/*TSS Tarea 5 Arbitro*/
		(unsigned short)	0x00,			/* limit[0:15]  */				// se inicializa en tss.c
		(unsigned short)	0x00,			/* base[0:15]   */				// se inicializa en tss.c
		(unsigned char)		0x00,			/* base[23:16]  */				// se inicializa en tss.c
		(unsigned char)		0x09,			/* type         */
		(unsigned char)		0x0,			/* s            */
		(unsigned char)		0x2,			/* dpl          */
		(unsigned char)		0x1,			/* p            */
		(unsigned char)		0x0,			/* limit[16:19] */				// estamos seguros que 16 bits nos alcanzan para cubrir sizeof(tss)
		(unsigned char)		0x00,			/* avl          */
		(unsigned char)		0x00,			/* l            */
		(unsigned char)		0x0,			/* db           */
		(unsigned char)		0x0,			/* g            */
		(unsigned char)		0x00,			/* base[31:24]  */				// se inicializa en tss.c
}
};

gdt_descriptor GDT_DESC = {
	sizeof(gdt) - 1,
	(unsigned int) &gdt
};
